define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'lands/land/index' + location.search,
                    add_url: 'lands/land/add',
                    edit_url: 'lands/land/edit',
                    del_url: 'lands/land/del',
                    multi_url: 'lands/land/multi',
                    import_url: 'lands/land/import',
                    table: 'land',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'ares', title: __('Ares'), operate: 'LIKE'},
                        {field: 'ares_status', title: __('Ares_status'), searchList: {"1":__('Ares_status 1'),"2":__('Ares_status 2')}, formatter: Table.api.formatter.status},
                        {field: 'types_id', title: __('Types_id')},
                        {field: 'money', title: __('Money'), operate: 'LIKE'},
                        {field: 'makeover', title: __('Makeover'), operate: 'LIKE'},
                        {field: 'duration', title: __('Duration'), searchList: {"1":__('Duration 1'),"2":__('Duration 2')}, formatter: Table.api.formatter.normal},
                        {field: 'landlord', title: __('Landlord'), operate: 'LIKE'},
                        {field: 'landlordmobile', title: __('Landlordmobile'), operate: 'LIKE'},
                        {field: 'property', title: __('Property'), searchList: {"1":__('Property 1'),"2":__('Property 2')}, formatter: Table.api.formatter.normal},
                        {field: 'extensive', title: __('Extensive'), operate: 'LIKE'},
                        {field: 'year', title: __('Year')},
                        {field: 'utypes', title: __('Utypes'), searchList: {"1":__('Utypes 1'),"2":__('Utypes 2'),"3":__('Utypes 3')}, formatter: Table.api.formatter.normal},
                        {field: 'icons_id', title: __('Icons_id')},
                        {field: 'see', title: __('See'), searchList: {"1":__('See 1'),"2":__('See 2')}, formatter: Table.api.formatter.normal},
                        {field: 'address_id', title: __('Address_id')},
                        {field: 'address', title: __('Address'), operate: 'LIKE'},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'detail',
                                    text: __('取消'),
                                    title: __('取消'),
                                    classname: 'btn btn-xs  btn-primary  btn-ajax',
                                    url: 'lands/land/qxtj',
                                    confirm: '确认取消推荐',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                    visible: function (row) {
                                        if (row.tj==1){
                                            return true;
                                        }
                                    },success:function (){
                                        location.reload()
                                    }
                                },
                                {
                                    name: 'detail',
                                    text: __('推荐'),
                                    title: __('推荐'),
                                    classname: 'btn btn-xs btn-success btn-magic btn-ajax',
                                    url: 'lands/land/settj',
                                    confirm: '是否要首页推荐',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                    visible: function (row) {
                                        if (row.tj ==0 ){
                                            return true;
                                        }
                                    },success:function (){
                                        location.reload()
                                    }
                                }
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
